package com.mjfeed;

import com.mjfeed.util.PropertiesLoader;
/**
 * @description 常量
 * @author zhaominglei
 * @date 2015年4月29日
 */
public class Constants {
	public static final String WINDOWS_ROOT_PATH = "C:"; //windows根路径
	public static final String LINUX_ROOT_PATH = "/usr/local"; //linux根路径
	public static final String DEST_EXTENSION_PRODUCTIMAGE = "jpg"; //商品图片生成图片处理任的目标扩展名
	public static final String DEST_CONTENT_TYPE_PRODUCTIMAGE = "image/jpeg"; //商品图片生成图片处理任的目标文件类型
	public static final long UPLOAD_MAX_SIZE = 10*1024*1024; //上传文件最大限制10M 
	
	public static final String DEFAULT_ENCODING = "UTF-8"; //默认编码
	
	protected static PropertiesLoader propertiesLoader = new PropertiesLoader("classpath:/config/mjfeed.properties");
	public static final String UPLOAD_IMAGE_EXTENSION = propertiesLoader.getProperty("upload.image.extension"); //上传图片扩展名
	public static final String UPLOAD_IMAGE_PATH = propertiesLoader.getProperty("upload.image.path"); //上传图片路径
	public static final String KINDEDITOR_UPLOAD_PATH = propertiesLoader.getProperty("kindeditor.upload.path"); //kindeditor上传路径
	
	public static final String UPLOAD_PATH_PREFIX_INDEXIMAGE = getUploadParentPath(UPLOAD_IMAGE_PATH) + "indexImage/"; //首页图片上传路径
	public static final String UPLOAD_PATH_PREFIX_PRODUCTCATEGORY = getUploadParentPath(UPLOAD_IMAGE_PATH) + "productCategory/"; //商品分类图片上传路径
	public static final String UPLOAD_PATH_PREFIX_PRODUCTIMAGE = getUploadParentPath(UPLOAD_IMAGE_PATH) + "productImage/"; //商品图片上传路径
	public static final String UPLOAD_PATH_PREFIX_KINDEDITOR = getUploadParentPath(KINDEDITOR_UPLOAD_PATH); //商品图片上传路径
	public static final String UPLOAD_PATH_PREFIX_COLLEGETOPIC = getUploadParentPath(UPLOAD_IMAGE_PATH) + "collegeTopic/"; //美嘉学院图片上传路径
	
	//上传时路径 操作系统不同 路径不同 这里服务器只有Windows和 Linux
	public static String getUploadParentPath(String parent) {
		String osname = System.getProperty("os.name", "Linux");
		if (osname != null && osname.indexOf("Windows") > -1) {
			return WINDOWS_ROOT_PATH+parent;
		} else if(osname != null && osname.indexOf("Linux") > -1) {
			return LINUX_ROOT_PATH+parent;
		} else {
			return parent;
		}
	}
	
	//下载时路径 操作系统不同 路径不同 这里服务器只有Windows和 Linux
	public static String getRealFilePath(String filepath) {
		if (filepath != null && filepath.indexOf(WINDOWS_ROOT_PATH) == 0) {
			filepath = filepath.replaceFirst(WINDOWS_ROOT_PATH, "");
		}
		if (filepath != null && filepath.indexOf(LINUX_ROOT_PATH) == 0) {
			filepath = filepath.replaceFirst(LINUX_ROOT_PATH, "");
		}
		return getUploadParentPath(filepath);
	}
}
